# -*- coding:utf-8 -*-
__author__ = 'Yangyang'
__date__ = '2017/9/14 14:28'
import re
from django import forms
from operation.models import UserAsk


class UserAskForm(forms.ModelForm):
    class Meta:
        model = UserAsk
        fields = ['name', 'mobile', 'course_name']

    def clean_mobile(self):
        mobile = self.cleaned_data['mobile']
        regex = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$"
        p = re.compile(regex)
        if p.match(mobile):
            return mobile
        else:
            return forms.ValidationError(u'手机号码非法', code='mobile_invalid')


